<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0903作业一：中北大学管理系统</title>
    <style>
        body{
            background-color: #6699F4;
        }
        .loginDiv{
            width: 550px;
            height: 550px;
            background-color: white;
            margin: 30px auto 0;
            text-align: center;
        }
        .username{
            width: 425px;
            height: 55px;
            border-radius: 5px;
            border: 1px solid lightgray;
        }
        .password{
            width: 426px;
            height: 55px;
            border-radius: 5px;
            border: 1px solid lightgray;
            margin-top:10px;
        }
        .loginButton{
            width: 426px;
            height: 55px;
            background-color: #FF6B4D;
            border-radius: 5px;
            color: white;
            font-size: 20pt;
            border-style: none;
            margin-top: 10px;
            margin-bottom: 18px;
        }
        .image{
            width: 200px;
            height: 75px;
        }
    </style>
</head>
<body>
<div class="loginDiv">
    <img class="image" src="image/nuc.png" style="margin-top:15px;" alt="中北图片">
    <h1>中北大学管理系统</h1>
    <form action="" method="post">
        <label>
            <input class="username" type="text" id="username" placeholder="请输入用户名" onblur="checkUsername()">
            <br>
            <span class="s1" id="s1"></span><br>
            <input class="password" type="password" id="password" placeholder="请输入密码" onblur="checkPwd()">
            <br>
            <span class="s2" id="s2"></span><br>
            <button class="loginButton">登录</button><br>
        </label>
    </form>
    <img src="image/qq.png" alt="QQ图片">
    <img src="image/weibo.png " alt="微博图片">
    <img src="image/weixin.png" alt="微信图片"><br>
</div>

<script>
    function checkUsername(){
        let ele = document.getElementById("username");
        let username = ele.value;
        let pattern = /^[a-zA-Z0-9_-]{4,16}$/;
        if(username === ""||username == null || username.length===0){
            ele.style.border = "1px solid red";
            document.getElementById("s1").innerHTML="<small style='color: red;'>用户名不能为空</small>"
        }else if(!pattern.test(username)){
            ele.style.border = "1px solid red";
            document.getElementById("s1").innerHTML="<small style='color: red;'>用户格式不正确</small>"
        }else {
            ele.style.border = "1px solid green";
            document.getElementById("s1").innerHTML=""
        }
    }
    function checkPwd(){
        let ele = document.getElementById("password");
        let password = ele.value;
        let pattern = /^[a-zA-Z0-9]{6,16}$/;;
        if(password === ""||password == null || password.length===0){
            ele.style.border = "1px solid red";
            document.getElementById("s2").innerHTML="<small style='color: red;'>密码不能为空</small>"
        }else if(!pattern.test(password)){
            ele.style.border = "1px solid red";
            document.getElementById("s2").innerHTML="<small style='color: red;'>密码格式不正确</small>"
        }else {
            ele.style.border = "1px solid green";
            document.getElementById("s2").innerHTML=""
        }
    }
</script>


</body>
</html>